<?php
/**
 * Created by PhpStorm.
 * User: xieky
 * Date: 2017/8/4
 * Time: 17:12
 */

namespace mybackend\controllers;


use common\services\myhtsq\IncomeService;

class IncomeController extends BaseController
{
    private $_incomeService;

    public function __construct($id, $module, IncomeService $incomeService, $config = array())
    {
        $this->_incomeService = $incomeService;
        parent::__construct($id, $module, $config);
    }

    /*
     * 获取收入项数据
     */
    public function actionGetIncomeList(){
        $incometype = $this->getParam('incometype','post');
        if(empty($incometype)){
            $this->errorParam();
        }

        $pageIndex = $this->getParam('pageIndex','post');
        if(empty($pageIndex)){
            $pageIndex = 1;
        }
        $pageSize = $this->getParam('pageSize','post');
        if(empty($pageSize)){
            $pageSize = 10;
        }
        $keyword = $this->getParam('keyword','post');
        $confirmtype = $this->getParam('confirmtype','post');
        $incomeresource = $this->getParam('incomeresource','post');

        $data = $this->_incomeService->getIncomeList($incometype,$pageIndex,$pageSize,$keyword,$confirmtype,$incomeresource);
        return $this->exportJson($data,0,'');
    }

    /**
     * 获取结转信息
     */
    public function actionGetCarryoverInfo(){
        $result = $this->_incomeService->getCarryoverInfo();
        return $this->exportJson($result,0,'');
    }

    /**
     * 执行结转操作
     */
    public function actionDoCarrover(){
        //获取结转方式
        $stype = $this->getParam('type','post');
        if($stype != 0 && $stype != 1 && $stype != 9){
            $this->errorParam();
        }
        $result = $this->_incomeService->doCarrover($stype);
        if($result === true){
            return $this->exportJson($result,0,'');
        }else{
            return $this->exportJson($result,999,$result);
        }
    }

    /**
     * 导出收入信息
     */
    public function actionExportIncome(){
        $incometype = $this->getParam('incometype','post');
        if(empty($incometype)){
            $this->errorParam();
        }
        $keyword = $this->getParam('keyword','post');
        if($keyword == 'undefined'){
            $keyword = '';
        }
        $confirmtype = $this->getParam('confirmtype','post');
        $incomeresource = $this->getParam('incomeresource','post');
        $data = $this->_incomeService->exportIncome($incometype,$keyword,$confirmtype,$incomeresource);
        $this->exportJson($data, $this->_incomeService->getErrCode(), $this->_incomeService->getErrMsg());
    }
}